function ActivityEraserController(calendarViewBody, eraserIcon) {
    this.register = function(calendar) {
        new EraserController(calendarViewBody, eraserIcon, new ActivityEraseMode(calendar)).register(calendar);
    };
}
function LocationEraserController(calendarViewBody, eraserIcon) {
    this.register = function(calendar) {
        new EraserController(calendarViewBody, eraserIcon, new LocationEraseMode(calendar)).register(calendar);
    };
}
function EraserController(calendarViewBody, eraseIcon, eraseMode) {
    this._calendarViewBody = calendarViewBody;
    this._eraseIcon = eraseIcon;
    this._eraseMode = eraseMode;
}

EraserController.prototype = {
    register: function(calendar) {
        var me = this;
        this._eraseIcon.onClick(function() {
            me._eraseIcon.activate();
            me._calendarViewBody.setMode(me._eraseMode);
        });

        this._eraseIcon.onActivated(function() {
            me._eraseIcon.removeTitle();
        });

        this._eraseIcon.onDeactivated(function() {
            me._eraseIcon.setTitle(i18n("LABEL_TURN_ON_CALENDER_ERASER"));
        });        
    }
};

function ActivityEraseMode(calendar) {
    this._calendar = calendar;
    this.cursor = 'calendar-erase-cursor';
}

ActivityEraseMode.prototype = {
    onSelection: function(sender, e) {
        var me =this;
        var dateRange = e.data.dateRange;
        this._calendar.beginTransaction();
        var dayModels = dateRange.toDayArray().select(function(date){
            return me._calendar.getDay(date);
        });
        var action = new EraseDayActivityAction(dayModels);
        me._calendar.applyAction(action);
    }
};
function LocationEraseMode(calendar) {
    this._calendar = calendar;
    this.cursor = 'calendar-erase-cursor';
}

LocationEraseMode.prototype = {
    onSelection: function(sender, e) {
        var me = this;
        var dateRange = e.data.dateRange;
        this._calendar.beginTransaction();
        var dayModels = dateRange.toDayArray().select(function(date) {
            return me._calendar.getDay(date);
        });
        var action = new EraseDayLocationAction(dayModels);
        me._calendar.applyAction(action);
    }
};